@echo off
echo ========================================
echo Eagle Project - Windows Setup Script
echo ========================================
echo.

:: 检查管理员权限
net session >nul 2>&1
if %errorLevel% == 0 (
    echo ✓ 管理员权限检查通过
) else (
    echo 警告: 建议以管理员身份运行此脚本
    echo 某些功能可能需要管理员权限
    pause
)

:: 检查 Chocolatey
echo [1/6] 检查包管理器...
where choco >nul 2>&1
if %errorLevel% == 0 (
    echo ✓ Chocolatey 已安装
) else (
    echo 安装 Chocolatey...
    powershell -Command "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"
    if %errorLevel% == 0 (
        echo ✓ Chocolatey 安装成功
    ) else (
        echo ✗ Chocolatey 安装失败，请手动安装
        echo 访问: https://chocolatey.org/install
        pause
    )
)

:: 检查 Go
echo [2/6] 检查 Go 环境...
go version >nul 2>&1
if %errorLevel% == 0 (
    echo ✓ Go 已安装
    go version
) else (
    echo 安装 Go...
    choco install golang -y
    if %errorLevel% == 0 (
        echo ✓ Go 安装成功
        echo 请重新打开命令提示符以使环境变量生效
    ) else (
        echo ✗ Go 安装失败
        pause
        exit /b 1
    )
)

:: 检查 Git
echo [3/6] 检查 Git...
git --version >nul 2>&1
if %errorLevel% == 0 (
    echo ✓ Git 已安装
    git --version
) else (
    echo 安装 Git...
    choco install git -y
    if %errorLevel% == 0 (
        echo ✓ Git 安装成功
    ) else (
        echo ✗ Git 安装失败
        pause
        exit /b 1
    )
)

:: 检查 Docker
echo [4/6] 检查 Docker...
docker --version >nul 2>&1
if %errorLevel% == 0 (
    echo ✓ Docker 已安装
    docker --version
) else (
    echo 安装 Docker Desktop...
    choco install docker-desktop -y
    if %errorLevel% == 0 (
        echo ✓ Docker Desktop 安装成功
        echo 请启动 Docker Desktop 并等待其完全启动
        echo 然后重新运行此脚本
        pause
        exit /b 0
    ) else (
        echo ✗ Docker Desktop 安装失败
        echo 请手动下载安装: https://www.docker.com/products/docker-desktop
    )
)

:: 检查 Make
echo [5/6] 检查 Make...
where make >nul 2>&1
if %errorLevel% == 0 (
    echo ✓ Make 已安装
    make --version
) else (
    echo 安装 Make...
    choco install make -y
    if %errorLevel% == 0 (
        echo ✓ Make 安装成功
    ) else (
        echo ✗ Make 安装失败，将跳过 Make 相关功能
    )
)

:: 配置 Go 环境
echo [6/6] 配置 Go 环境...
echo 设置 Go 代理...
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOSUMDB=sum.golang.google.cn
go env -w GO111MODULE=on

echo 安装必要的 Go 工具...
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/google/wire/cmd/wire@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0
go install github.com/swaggo/swag/cmd/swag@latest

echo.
echo ========================================
echo 环境配置完成!
echo ========================================
echo.
echo 下一步操作:
echo 1. 编辑 config\config.local.yaml 配置数据库连接
echo 2. 运行 scripts\start-dev.bat 启动开发环境
echo 3. 或运行 go run cmd/server/main.go cmd/server/wire_gen.go
echo.
echo 常用命令:
echo - 开发启动: scripts\start-dev.bat
echo - 生产部署: powershell -ExecutionPolicy Bypass -File scripts\deploy-prod.ps1
echo - 代码检查: golangci-lint run
echo - 运行测试: go test ./...
echo.
echo 文档: README.md
echo.

pause 